package com.wudi;

public class UtilsCreateCar {

    public static Car CreateCar() {
        ICarFactory factory; //接口实例化
        try {
            //反射
            Class classReflection = Class.forName(UtilsXML.ReadNameFromXML());//读XML中节点名
            Object objectReflection = classReflection.newInstance();
            factory = (ICarFactory) objectReflection; //XML中定义的工厂类反射到实例中

            Car car = factory.carFactoryMethor();//开始造车
            System.out.println(car.showInfo());
            return car;
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        return null;
    }

    public static Car CreateCar(Integer no) {
        ICarFactory factory; //接口实例化
        try {
            //反射
            Class classReflection = Class.forName(UtilsXML.ReadNameFromXML(no));//读XML中节点名
            Object objectReflection = classReflection.newInstance();
            factory = (ICarFactory) objectReflection; //XML中定义的工厂类反射到实例中

            Car car = factory.carFactoryMethor();//开始造车
            System.out.println(car.showInfo());
            return car;
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        return null;
    }
}

